﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using _4T.Data;
using _4T.BLL;

namespace _4T
{
    public partial class CMS_ConfirmAccount : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["u"] != null)
            {
                if (!IsPostBack)
                {
                    LoadPersonalInfo(Request.QueryString["u"].ToString());
                }
            }
            
        }

        private void LoadPersonalInfo(string personalCode)
        {
            PersonalInfo person = new PersonalInfoBLL().GetPersonalInfo(personalCode);
            if (person != null)
            {
                hdfPersonalCode.Value = person.PersonalCode;
                lblUsername.Text = person.Username;
                lblFullName.Text = person.FullName;
                lblEmail.Text = person.Email;
                lblPhoneNumber.Text = person.PhoneNumber;
                chkIsPropose.Checked = person.IsPropose;
                chkIsFilter.Checked = person.IsFilter;
                chkIsVerify.Checked = person.IsVerify;
                chkIsApprove.Checked = person.IsApprove;
                chkIsPayment.Checked = person.IsPayment;
            }
        }

        protected void btnConfirm_Click(object sender, EventArgs e)
        {            
            int result = new PersonalInfoBLL().UpdatePersonalInfo(hdfPersonalCode.Value, null, null, null, null, null, null, null, GetRole(), ConvertRights());
        }

        private string ConvertRights()
        {
            if (chkIsPropose.Checked || chkIsFilter.Checked || chkIsVerify.Checked || chkIsApprove.Checked || chkIsPayment.Checked)
            {
                string rights = string.Empty;
                rights += Convert.ToInt32(chkIsPropose.Checked).ToString();
                rights += Convert.ToInt32(chkIsFilter.Checked).ToString();
                rights += Convert.ToInt32(chkIsVerify.Checked).ToString();
                rights += Convert.ToInt32(chkIsApprove.Checked).ToString();
                rights += Convert.ToInt32(chkIsPayment.Checked).ToString();
                rights += "0";
                return rights;
            }
            else
            {
                return "0";
            }
        }

        private int GetRole()
        {
            if (chkIsPayment.Checked) return 6;
            if (chkIsApprove.Checked) return 5;
            if (chkIsVerify.Checked) return 4;
            if (chkIsFilter.Checked) return 3;
            if (chkIsPropose.Checked) return 2;
            return 0;
        }
    }
}